// 地址

const addressesModel = require("../model/addressesModel");

// require("../model/usersModel");

//增加匹配 
module.exports.insert = async function (content) {
    return await addressesModel.create(content);
}


//删除匹配
module.exports.delete = async function (id) {
    return await addressesModel.deleteOne({ _id: id });
}

//修改匹配
module.exports.update = async function (id, content) {
    return await addressesModel.updateOne({ _id: id }, content);
}

//分页所有/条件查询
module.exports.find = async function (searchObj, page) {
    console.log(searchObj);
    let { current, size } = page;
    let total = await addressesModel.countDocuments(searchObj);
    let totalPage = Math.ceil(total / size);
    let rows = await addressesModel.find(searchObj)
    .populate({ path: 'userId' })
    .limit(parseInt(size)).skip((current - 1) * size);
    return { current, size, total, totalPage, rows };
}